<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <script src="../vue.js"></script>
  </head>

  <body>
    <div id="app">
      <button @click="changePerson">改变数据</button>
      <div>person--->{{person}}</div>
    </div>
    <script>
      Vue.config.productionTip = false;

      const vm = new Vue({
        el: "#app",
        data() {
          return {
            person: {
              name: "余维海",
              age: 30,
            },
          };
        },
        methods: {
          changePerson() {
            /* 
              因为vue2响应式原理的底层原理无法监听对象的删除和新增
              vue2新提供了两个方法,可以响应式的新增和删除对象的属性(Vue.set()和Vue.delete() 或者 this.$set()和this.$delete())
            */
            //新增
            // this.$set(this.person, "sex", "男");
            // Vue.set(this.person, "sex", "男");
            // console.log(this.$set === Vue.set);//同一个方法放在两个不同的地方

            //删除
            // this.$delete(this.person, "age");
            Vue.delete(this.person, "age");
          },
        },
      });
    </script>
  </body>
</html>
